<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>芭蕉花管理平台登录</title>
	<link rel="shortcut icon" type="image" href="/img/login/logo.png">
	<link rel="stylesheet" href="/css/bootstrap.min.css">
	<link  rel="stylesheet" href="/css/login.css">
	<script type="text/javascript" src="/js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="/js/bootstrap/bootstrap.min.js"></script>
	<script type="text/javascript">
		if (top != self) {
			parent.location.href = '/login.html';
		} else {
			var pathname = window.location.pathname;
			if (pathname != "/login.html") {
				location.href = '/';
			}
		}
	</script>
</head>
<body>
<div style="min-width: 494px; background: url('/img/login/background.png'); moz-background-size: 100%; -o-background-size: 100%; -webkit-background-size: 100%; background-size: 100%; background-repeat-y: repeat;">
<div class="header container-fluid">
	<div class="" style="margin: 30px auto;" >
		<!-- logo预留 -->
		<img class=" logo" id="logo"   />
		<span class="bg_blue"  style="color: #ffffff;position: absolute;top:46px;">&nbsp; 芭蕉花管理平台</span>
	</div>
</div>
<div class="container-fluid bg-content">
	<div class="login-content">
		<div style="text-align: center"><font style="color:#ffffff;font-size: 30px;">管理员登录</font></div>
		<div  id="msg" align="center"  style="color: red;height: 20px;"></div>
			<form id="login-form" method="post" onsubmit="return false;">
				<input type="text" id="userName" name="userName"  placeholder="请输入用户名" />
				<input type="password" id="password" name="password"  placeholder="请输入密码"/>
				<button class="login-submit"  type="submit" onclick="login(this)">登&nbsp;&nbsp;录</button>
			</form>
	</div>
</div>
<div class="container-fluid login-copyright">
    <p id="copyright" style="color: #ffffff;margin-top: 35px;">版权所有 © 2020 成都芭蕉花信息技术服务有限公司</p>
</div>
</div>
</body>

<script type="text/javascript">

	$(document).ready(function() {
		//初始化数据
		$.ajax({
			type : 'post',
			url : '/sys/getAdminSysInfo',
			success : function(res) {
				var res = res.data.info;
				var str = "";
				for (var i = 0; i < res.length; i++) {
					if (res[i].keys == 'copyright') {
						str += res[i].value;
					}
				}
				for (var i = 0; i < res.length; i++) {
					if (res[i].keys == 'company') {
						str += " ";
						str += res[i].value;
					}
					if (res[i].keys == 'logo') {
						$("#logo").attr("src", res[i].value);
					}
				}
				$("#copyright").text(str);
			},
		});
	});

	var user = loginInfo();
	if (user != "") {
		location.href = '/';
	}

	function login(obj) {
		$(obj).attr("disabled", true);

		var userName = $.trim($('#userName').val());
		var password = $.trim($('#password').val());
		if (userName == "" || password == "") {
			$("#msg").html('用户名或者密码不能为空');
			$(obj).attr("disabled", false);
		} else {
			$.ajax({
				type : 'post',
				url : '/sys/login',
				data : $("#login-form").serialize(),
				success : function() {
					location.href = '/';
				},
				error : function(xhr, textStatus, errorThrown) {
					var msg = xhr.responseText;
					var response = JSON.parse(msg);
					$("#msg").html(response.message);
					$(obj).attr("disabled", false);
				}
			});

		}
	}

	// 检查登录状态
	function loginInfo() {
		var user = "";
		$.ajax({
			type : 'post',
			url : '/sys/getLoginInfo',
			async : false,
			success : function(data) {
				if (data != null && data != "") {
					user = data.data.userInfo;
				}
			},
			error : function(xhr, textStatus, errorThrown) {
				var msg = xhr.responseText;
				var response = JSON.parse(msg);
				$("#info").html(response.message);
			}
		});

		return user;
	}
</script>
</html>